<template>
  <div>
    <van-cell title="验收人" is-link :value="header.ysr" @click="clickAction(1)" />
    <van-cell title="保管人" is-link :value="header.bgr" @click="clickAction(2)" />
    <van-cell title="仓库" is-link :value="header.stockName" @click="clickAction(3)" />

    <item-select ref="select" @select="selectAction"></item-select>
  </div>
</template>
<script>
import ItemSelect from "../../../components/ItemSelect";
import tools from "../../../../tools/tools";
import comm from "../../../../tools/comm";
import ui from "../../../../tools/ui";
import api from "../../../../tools/api";
export default {
  components: {
    ItemSelect
  },
  data() {
    return {
      EMP_CLASSID: 3, //职员
      STOCK_CLASSID: 5, //仓库
      clickType: 1,
      deliveryNoteNo: 0, // 送货单号
      header: {
        ysr: "请选择",
        ysrId: 11799,
        bgr: "请选择",
        bgrId: 11799,
        stockName: "请选择",
        stockId: 0
      }
    };
  },
  methods: {
    selectAction(item) {
      // console.log(JSON.stringify(item));
      if (this.clickType == 1) {
        this.header.ysr = item.name;
        this.header.ysrId = item.value.FItemID;
      } else if (this.clickType == 2) {
        this.header.bgr = item.name;
        this.header.bgrId = item.value.FItemID;
      } else if (this.clickType == 3) {
        //批改仓库信息
        this.header.stockName = item.name;
        this.header.stockId = item.value.FItemID;
        this.batchChangeStockInfo();
      }
      // console.log(JSON.stringify(this.header));
      this.$refs.select.hide();
    },
    clickAction(type) {
      this.clickType = type;
      if (type == 1 || type == 2) {
        this.$refs.select.show(this.EMP_CLASSID);
      } else if (type == 3) {
        if (this.deliveryNoteNo) {
          this.$refs.select.show(this.STOCK_CLASSID);
        } else {
          ui.dialog({
            msg: "请先扫码，获取送货单信息"
          });
        }
      }
    },
    //批改仓库信息
    batchChangeStockInfo() {
      ui.showLoading();
      let self = this;
      api.ajax({
        methodName: "app/updateItemStockIdByDeliveryNoteNo",
        data: {
          deliveryNoteNo: self.deliveryNoteNo,
          stockId: self.header.stockId,
          stockName: self.header.stockName
        },
        s(code, res) {
          console.log(JSON.stringify(res));
          if (code == 1) {
            self.$emit("updateList");
          }
          ui.hideLoading();
        }
      });
    },
    checkData() {
      let flag = true;
      if (!this.header.ysrId) {
        ui.dialog({
          msg: " 请选择验收人"
        });
        flag = false;
      }
      if (!this.header.bgrId) {
        ui.dialog({
          msg: " 请选择保管人"
        });
        flag = false;
      }
      return flag;
    },
    /**
     * orderType 1:外购，2委外加工
     */
    getHeader() {
      let pageHeader = {
        FFManagerID: this.header.ysrId, //验收人
        FSManagerID: this.header.bgrId //保管人
      };
      return pageHeader;
    }
  }
};
</script>
